package ac.svn.accesscontrol.utils;

import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.swing.ImageIcon;


public class Utility 
{
	//Member variables
	private static Map<String,Image> imageCache = new HashMap<String, Image>();
	public static Map<String, ImageIcon> iconCache = new HashMap<String, ImageIcon>();
	
	public static String getGUID()
	{
		return UUID.randomUUID().toString();
	}
	
	public static Image getImage(String url)
	{
		Image image = imageCache.get(url);
		if(null == image)
		{
			System.out.println("[Utils] Fetching Image: " + url);
			image = Toolkit.getDefaultToolkit().getImage(Utility.class.getClassLoader().getResource(url));
			imageCache.put(url, image);
		}
		return image;
	}
	
	public static ImageIcon getImageIcon(String url)
	{
		ImageIcon icon = iconCache.get(url);
		if(null == icon)
		{
			Image image = Toolkit.getDefaultToolkit().getImage(Utility.class.getClassLoader().getResource(url));
			icon = new ImageIcon(image);
			iconCache.put(url, icon);
		}
		return icon; 
	}

	
}
